
using System;

namespace TypingMonkey
{
	
	public class Target
	{
		public string targetword;
		private int length;
		private string check;
		public event TargetReachedEventHandler TargetReachedEvent;

		
		public Target(string target)
		{
			this.targetword = target;
			this.length = target.Length;
			this.check = this.targetword;
		}

		public void newData(char newchar)
		{
			check += newchar.ToString();
			check = check.Substring(1);
			if ((check == targetword))
				OnTargetReachedEvent();
		}
		
		private void OnTargetReachedEvent()
		{
			TargetReachedEvent();
		}
		
		public void SubscribeTargetReachedEvent(TargetReachedEventHandler eventHandler)
		{
			TargetReachedEvent += eventHandler;
		}

	}
}
